package com.kh.pajx.sop.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kh.pajx.sop.base.BaseServiceImpl;
import com.kh.pajx.sop.dao.ISysUserRoleDao;
import com.kh.pajx.sop.domain.PageBean;
import com.kh.pajx.sop.domain.SysUserRole;
import com.kh.pajx.sop.service.ISysUserRoleService;
import com.kh.pajx.sop.util.page.QueryHelper;

/**
 * 用户角色信息业务逻辑实现类
 * @author:	azzcsimp
 * @Createdate:	2014年7月17日 下午8:21:44
 */
@Service
@Transactional
public class SysUserRoleServiceImpl extends BaseServiceImpl<SysUserRole> implements ISysUserRoleService {

	@Resource
	private ISysUserRoleDao sysUserRoleDao;
	
	/**
	 * 添加用户角色信息
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#save(java.lang.Object)
	 */
	@Override
	public void save(SysUserRole userRole) {
		sysUserRoleDao.save(userRole);
	}
	
	/**
	 * 修改用户角色信息
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#update(java.lang.Object)
	 */
	@Override
	public void update(SysUserRole demo) {
		sysUserRoleDao.update(demo);
	}
	
	/**
	 * 删除用户角色信息
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#delete(java.lang.String)
	 */
	@Override
	public void delete(String uuid) {
		sysUserRoleDao.delete(uuid);
	}
	
	/**
	 * 查找用户角色信息
	 * @param uuid
	 * @return   
	 * @author:	azzcsimp
	 * @Createdate:	2014年7月18日 下午5:30:01
	 */
	@Override
	public SysUserRole getById(String uuid) {
		return sysUserRoleDao.getById(uuid);
	}
	
	/**
	 * 分页获取用户角色信息
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#getPageBean(int, int, com.kh.pajx.sop.util.page.QueryHelper)
	 */
	@Override
	public PageBean getPageBean(int pageNum, int pageSize,
			QueryHelper queryHelper) {
		return sysUserRoleDao.getPageBean(pageNum, pageSize, queryHelper);
	}
	
	/**
	 * 获取用户角色编码
	 * @see com.kh.pajx.sop.service.ISysUserRoleService#getUsrCode(java.lang.String)
	 */
	@Override
	public String getUsrCode(String usgCode) {
		String usrCode = sysUserRoleDao.getMaxUsrCode(usgCode);
		if (StringUtils.isNotEmpty(usrCode)) {
			return (Integer.parseInt(usrCode) + 1) + "";
		} else{
			return (Integer.parseInt(usgCode) + 1) + "";
		}
	}
	
	/**
	 * 根据用户组编码获取该用户组下用户角色信息列表
	 * @see com.kh.pajx.sop.service.ISysUserRoleService#findUserRoleByGroupCode(java.lang.String)
	 */
	@Override
	public List<SysUserRole> findUserRoleByGroupCode(String usgCode) {
		return sysUserRoleDao.findUserRoleByGroupCode(usgCode);
	}
	
	/**
	 * 根据用户组编码统计该用户组下的用户角色数据
	 * @see com.kh.pajx.sop.service.ISysUserRoleService#countUserRoleByGroupCode(java.lang.String)
	 */
	@Override
	public long countUserRoleByGroupCode(String usgCode) {
		return sysUserRoleDao.countUserRoleByGroupCode(usgCode);
	}
	
	/**
	 * 查询所有用户角色信息
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#findAll()
	 */
	@Override
	public List<SysUserRole> findAll() {
		return sysUserRoleDao.findAll();
	}
	
	@Override
	public SysUserRole getUserRoleByCode(String usrCode) {
		return sysUserRoleDao.getUserRoleByCode(usrCode);
	}
}
